#!/bin/bash 

source head.sh

action=$1

# 查看所有计算节点的虚拟机列表
if [ "list" == "$action" ]; then
  for hpv in ${hpvList[@]}; do
    echo "======================= vm in $hpv ============================="
    virsh -c qemu+tcp://$hpv/system list | grep -v Name | grep -v "\-\-\-"
  done
# 查看学生使用VPN登录的记录
elif [ "log" == "$action" ]; then
  $mysqllogin "select from_unixtime(lab_log.time), lab_user.user_name, lab_user.real_name, lab_log.ipaddr from lab_log join lab_user on lab_log.user_id=lab_user.user_id;"
# 关闭掉所有路由器和虚拟机
elif [ "destroy" == "$action" ]; then
  for hpv in ${hpvList[@]}; do
    echo "======================= vm in $hpv ============================="
    virsh -c qemu+tcp://$hpv/system destroy $2
  done
fi
